﻿// -----------------------------------------------------------------------------------------------
//  <copyright file="TfsTestImageHelper.cs" company="http://buginbox.wordpress.com/">
//    Copyright (c) GNU General Public License version 2 (GPLv2)
//  </copyright>
// <summary>
//    Copied/updated from http://blogs.microsoft.co.il/blogs/shair/archive/2010/07/06/tfs-api-part-27-test-plans-test-suites-test-cases-mapping.aspx Refer to articles index : http://blogs.microsoft.co.il/blogs/shair/archive/2011/05/18/tfs-api-index-parts-1-to-37.aspx
//    Cf. Shai Raiten from http://blogs.microsoft.co.il/blogs/shair/
// </summary>
// -----------------------------------------------------------------------------------------------

using System;
using System.Drawing;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;
using System.Windows.Media.Imaging;

using Image = System.Windows.Controls.Image;

namespace TestPlanMigration.Tree
{
    /// <summary>
    /// The image helpers.
    /// </summary>
    public static class TfsTestImageHelper
    {
        /// <summary>
        /// The get image source.
        /// </summary>
        /// <param name="bitmap">The bitmap.</param>
        /// <returns></returns>
        public static BitmapSource GetImageSource(Bitmap bitmap)
        {
            return Imaging.CreateBitmapSourceFromHBitmap(
                bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
        }

        /// <summary>
        /// The create header.
        /// </summary>
        /// <param name="title">The title.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public static StackPanel CreateHeader(string title, TfsTestItemType type)
        {
            var panel = new StackPanel { Orientation = Orientation.Horizontal };
            var lbl = new Label { Content = title };
            var img = new Image();

            switch (type)
            {
                case TfsTestItemType.TestCase:
                    img.Source = TfsTestImageHelper.GetImageSource(Properties.Resources.TestCase);
                    break;

                case TfsTestItemType.TestSuite:
                    img.Source = TfsTestImageHelper.GetImageSource(Properties.Resources.Suite);
                    break;

                case TfsTestItemType.TestPlan:
                    img.Source = TfsTestImageHelper.GetImageSource(Properties.Resources.Plan);
                    break;

                case TfsTestItemType.TeamProject:
                    img.Source = TfsTestImageHelper.GetImageSource(Properties.Resources.TeamProject);
                    break;
            }

            panel.Children.Add(img);
            panel.Children.Add(lbl);

            return panel;
        }
    }
}